<template>
	<view>
		<view class="solid-bottom padding-bottom flex justify-center ">
			<image src="https://img1.baidu.com/it/u=2081871846,4015492109&fm=26&fmt=auto" mode="widthFix" style="margin-top: 200rpx;"></image>
		</view>
		<view class="padding margin-top-xl">
			<view>
				申请获取以下权限
			</view>
			<view class="margin-top text-gray">
				获取您的公开信息（昵称，头像等）
			</view>
		</view>
		<view class="padding text-center bg-green round margin margin-top-xl" @click="getUserProfile">
			授权登录
		</view>

	</view>
</template>

<script>
	import {
		post_login
	} from '@/common/path.js'
	const app = getApp()
	export default {
		data() {
			return {
				loginData: {}, //用户信息
				loginCode: '',

			}
		},
		onLoad() {

		},
		methods: {
			/**
			 * 获取用户信息
			 */
			getUserProfile() {
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						let obj = JSON.parse(res.rawData)
						let data = {
							userName: obj.nickName,
							avatar: obj.avatarUrl,
							openId: uni.getStorageSync('openId')
						}
							this.loginSet(data)
					}
				})
			},
			//登录
			loginSet(data) {
				let _ts = this
				_ts.Http.POST(post_login, data)
					.then((res) => {
						console.log('[用户信息]', res);
						if (res.code == 0) {
							this.$tools.showToast('登录成功')
							uni.setStorageSync('userInfo',res.data)
							setTimeout(r => {
								uni.navigateBack({
									delta:1
								})
							}, 1000)
						} else {
							_ts.$tools.showToast(res.msg)
						}
					})
			}
		}
	}
</script>

<style>
	image {
		height: 200rpx;
		width: 200rpx;
	}

	.submit_bottom {
		background-color: white;
		border-radius: 15rpx;
		width: 690rpx;
	}
</style>
